import redis

class MyRedis:
    def __init__(self):
        self.redis = redis.Redis(host='127.0.0.1', port=6379, db=1)
    # 字符串的添加
    def set_str(self, key, value):
        self.redis.set(key, value)


    # 设置时间字符串的添加
    def set_time_str(self, key,time, value):
        self.redis.setex(key,time, value)



    def get_str(self, key):
        value = self.redis.get(key)
        if value:
            return value.decode('utf-8')

    def del_str(self, key):
        self.redis.delete(key)

    # 集合添加数据
    def get_set(self, key,len):
        return self.redis.zrevrange(key,0,len)

    def isexist(self,key):
        return self.redis.exists(key)

    def settime(self,key,time):
        return self.redis.expire(key,time)

    # 集合权重
    def set_score(self, key, value):
        return self.redis.zincrby(key,1,value)

myredis = MyRedis()




